Skip to content

Handle String-like and IO-like objects for Ripper.sexp#3891

Merged
kddnewton merged 1 commit into
ruby:mainfrom
eregon:ripper-sexp-coerce
Jan 30, 2026
Merged

Handle String-like and IO-like objects for Ripper.sexp#3891
kddnewton merged 1 commit into
ruby:mainfrom
eregon:ripper-sexp-coerce

Conversation

@eregon

@eregon eregon commented Jan 29, 2026

Copy link
Copy Markdown
Member

@eregon
eregon requested review from Earlopain and kddnewton January 29, 2026 19:41
@eregon
eregon force-pushed the ripper-sexp-coerce branch from 5bbfbcf to 6e1d9e9 Compare January 29, 2026 19:52

@Earlopain Earlopain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the rules are a bit more complex: https://github.com/ruby/ruby/blob/acc414572c213f2690eee56bac3d2355a24e5930/ext/ripper/ripper_init.c.tmpl#L357-L376

Do you want to implement those also? File should be easy at least.

Comment thread test/prism/ruby/ripper_test.rb Outdated
@eregon

eregon commented Jan 29, 2026

Copy link
Copy Markdown
Member Author

It looks like the rules are a bit more complex: https://github.com/ruby/ruby/blob/acc414572c213f2690eee56bac3d2355a24e5930/ext/ripper/ripper_init.c.tmpl#L357-L376

Do you want to implement those also? File should be easy at least.

I see. If you want to do it feel free to push to this branch, otherwise I can get to it tomorrow or so.

@Earlopain

Copy link
Copy Markdown
Collaborator

Tomorrow is fine

@eregon
eregon force-pushed the ripper-sexp-coerce branch from 6e1d9e9 to a83cb7b Compare January 30, 2026 11:58
@eregon

eregon commented Jan 30, 2026

Copy link
Copy Markdown
Member Author

Done, now it also handles IO object (= T_FILE) and #gets objects, same logic as upstream.

@eregon
eregon requested a review from Earlopain January 30, 2026 11:59
@eregon eregon changed the title Handle String-like objects for Ripper.sexp Handle String-like and IO-like objects for Ripper.sexp Jan 30, 2026
def initialize(source, filename = "(ripper)", lineno = 1)
@source = source
if source.is_a?(IO)
@source = source.read

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be backed by Prism.parse_stream but since we need the whole source anyways I think this is fine. BTW, wouldn't work for the gets case since prism also expects eof? to be present

end
else
@source = source.to_str
end

This comment was marked as duplicate.

Comment thread lib/prism/translation/ripper.rb
@kddnewton
kddnewton merged commit 62c7300 into ruby:main Jan 30, 2026
66 checks passed
@kddnewton

Copy link
Copy Markdown
Collaborator

Just following up on this since I saw the mention of RSpec: rspec/rspec#303.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants